<?php

namespace App\View\Components;

use BaconQrCode\Renderer\Image\SvgImageBackEnd;
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;
use Closure;
use Filament\Facades\Filament;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class ReferMessage extends Component
{
    /**
     * Create a new component instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     */
    public function render(): View|Closure|string
    {
        $renderer = new ImageRenderer(
            new RendererStyle(150, 1),
            new SvgImageBackEnd()
        );
        $writer = new Writer($renderer);
        $referralLink = route('filament.user.auth.register'). "?refer=".Filament::auth()->getUser()->referral_code;
        $qrcode = $writer->writeString($referralLink);
        $qrcode = str_replace('<?xml version="1.0" encoding="UTF-8"?>', "", $qrcode);
        return view('components.refer-message', ['referralLink' => $referralLink, 'qrcode' => $qrcode]);
    }
}
